package com.example.myapplication;

import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

import androidx.activity.EdgeToEdge;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.graphics.Insets;
import androidx.core.view.ViewCompat;
import androidx.core.view.WindowInsetsCompat;

import com.example.myapplication.utils.DateUtil;

public class ActiveButton extends AppCompatActivity {

    private Button btn;
    private TextView text;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        EdgeToEdge.enable(this);
        setContentView(R.layout.activity_active_button);


        btn = findViewById(R.id.login_btn);
        text = findViewById(R.id.text_view);

        ((Button) btn).setOnClickListener(new MyClickListener(text));
    }


//    public void doClick(View view) {
//        String now = DateUtil.getNowTime();
//        CharSequence btnLabel = ((Button) view).getText();
//        String desc = String.format("%s 点击 %s", now, btnLabel);
//        text.setText(desc);
//    }

    static class MyClickListener implements View.OnClickListener {

        private final TextView text;

        public MyClickListener(TextView text) {
            this.text = text;
        }

        @Override
        public void onClick(View view) {
            String now = DateUtil.getNowTime();
            CharSequence btnLabel = ((Button) view).getText();
            String desc = String.format("%s 点击了按钮: %s", now, btnLabel);
            text.setText(desc);
        }
    }
}